Ext.ns('App', 'App.control');





App.control.mapField = Ext.extend(Ext.Window, {
	map: null,
	featureLayer: null,
	onCancel: function(btn, e){
		this.hide()
	},
	onOK: function(btn, e){
		
		//check if only one polygon is drawn		
		if (vector.features.length>1) {
			actions["edit"].control.deactivate();
			actions["drawpolygon"].control.deactivate();
			Ext.MessageBox.alert('Warning', 'Only one polygon is allowed.');
			return
		} else if  (vector.features.length==0) {
			Ext.MessageBox.alert('Warning', 'No polyon was drawn.');
			return
		}
		
		//save the geometry in the field
		var geojson_format = new OpenLayers.Format.GeoJSON();
		//transform the geometry
		var geom = vector.features[0].geometry.clone().transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326")); 

		this.form.getForm().findField('geometry').setValue(geojson_format.write(geom));
		this.hide()	
		
	},
	clearFeatures: function(){
		var polygonLayer = this.polygonLayer;
		var pointLayer = this.polylineLayer;	
	},
	
    initComponent: function(){
        var config = {
			modal: true,
			maximizable: true,
			layout: 'fit', //in IE it wouldn't draw the panel correctly if this is not specifically defined.
            items: {
				xtype: 'mappanel',
				id: 'app-mappanel'
			},
			closeAction: 'hide'
			,buttons: [{
				text: 'OK',
				handler: this.onOK,
				scope: this
			}, {
				text: 'Cancel',
				handler: this.onCancel,
				scope: this
			}]
        }; // eo config object
        // apply config
		
		
        Ext.apply(this, Ext.apply(this.initialConfig, config));
        
        App.control.mapField.superclass.initComponent.apply(this, arguments);
    } // eo function initComponent
//    ,onRender: function(){
//        this.store.load();
//        
//        App.control.mapField.superclass.onRender.apply(this, arguments);
//    } // eo function onRender
});

Ext.reg('mapfield', App.control.mapField);


